package org.luckystrophe.snowtoms.model.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.luckystrophe.snowtoms.model.JsonRequestPOST;

import android.view.View;

public class UserPost {

	private String comment;
	private long userId;

	private String imgSrc;
	private String userThumbnail;
	private String name;

	private String userLocation;

	private boolean like;
	private boolean dislike;

	private long msgId;
	private int replyCount;
	private int likeCounts;

	private int msg_type;

	private Date postDate;

	private SimpleDateFormat sdf = new SimpleDateFormat("a hh:mm", Locale.KOREA);
	private SimpleDateFormat sdf2 = new SimpleDateFormat("MM월 dd일, a hh:mm", Locale.KOREA);

	public UserPost(String comment, long msgId, int replyCount, int likeCounts, String imgSrc, String userThumbnail,
			long userId, String userLocation, String name, boolean like, boolean dislike, Date postDate, int msg_type) {
		this.comment = comment;
		this.msgId = msgId;
		this.replyCount = replyCount;
		this.likeCounts = likeCounts;
		this.imgSrc = JsonRequestPOST.REMOTE_SNOWTOMS_IMAGE + imgSrc;
		this.userLocation = userLocation;
		this.userThumbnail = userThumbnail;
		this.userId = userId;
		this.dislike = false;
		this.name = name;
		this.like = like;
		this.dislike = dislike;
		this.postDate = postDate;
		this.msg_type = msg_type;
	}

	public String getUserLocation() {
		return userLocation;
	}

	public String getComment() {
		return comment;
	}

	public long getPostNo() {
		return msgId;
	}

	public int getReplyCount() {
		return replyCount;
	}

	public int getLikeCounts() {
		return likeCounts;
	}

	public String getImgSrc() {
		return imgSrc;
	}

	public long getUserId() {
		return userId;
	}

	public String getUserThumbnail() {
		return userThumbnail;
	}

	public boolean isDislike() {
		return dislike;
	}

	public boolean isLike() {
		return like;
	}

	public String getName() {
		return name;
	}

	public String getPostDate() {
		long compare = System.currentTimeMillis() - postDate.getTime();
		long dateCompare = compare / (24 * 60 * 60 * 1000);

		if (dateCompare == 1) {
			return "어제, " + sdf.format(postDate);
		} else if (dateCompare > 1) {
			return sdf2.format(postDate);
		} else {
			return "오늘, " + sdf.format(postDate);
		}

	}

	public void setLike(boolean like) {
		this.like = like;
	}

	public void setDislike(boolean dislike) {
		this.dislike = dislike;
	}

	public int getMsgType() {
		return msg_type;
	}

	public String getLocationAndLikes() {
		StringBuffer sb = new StringBuffer();
		if (!userLocation.equals("null")) {
			sb.append("#").append(userLocation);
		}

		if (this.likeCounts != 0) {
			if (sb.length() != 0) {
				sb.append(" / ");
			}
			sb.append("좋아요 " + likeCounts + "개");
		}

		if (this.replyCount != 0) {
			if (sb.length() != 0) {
				sb.append(" / ");
			}
			sb.append("댓글 " + replyCount + "개");
		}
		return sb.toString();
	}

	public int isMyPost(long myId) {
		if (myId == 0L) {
			return View.INVISIBLE;
		}
		return myId == userId ? View.VISIBLE : View.INVISIBLE;
	}

}
